package com.xiaomi.util;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class ToolsUtil {
    public static int num = 0;

    //根据年月日+序列号生成订单编号
    public static String orderNum() {
        //yyyy年MM月dd日 HH:mm:ss E
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyyMMdd");
        LocalDateTime ldt = LocalDateTime.now();
        String orderNum = ldt.format(dtf);

        ++num;
        if (num > 99999) {
            num = 0;
        }

        if (num < 10) {
            orderNum += "0000" + num;
        } else if (num >= 10 && num < 100) {
            orderNum += "000" + num;
        } else if (num >= 100 && num < 1000) {
            orderNum += "00" + num;
        } else if (num >= 1000 && num < 10000) {
            orderNum += "0" + num;
        } else {
            orderNum += num;
        }

        return orderNum;
    }

    //根据传入的原文件名，生成新文件名
    public static String  getFileNewName(String oldFileName) {
        String ext = oldFileName.substring(oldFileName.lastIndexOf(".")) ;
        String fileNewName = System.currentTimeMillis() + ext ;

        return fileNewName ;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {
            System.out.println(ToolsUtil.orderNum());
        }
    }
}
